<#include "./template/general_temp.ftl">

<#macro content>
<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-comments"></i>评论管理</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content">
                <div class="box col-md-12">
                    <form class="form-inline" role="form">
                        <div class="form-group">
                            <input type="text" style="width: 300px;" class="form-control" id="searchContent" placeholder="请输入要查询的评论内容（模糊查询）"/>
                        </div>
                        <button type="button" onclick="queryData()" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
                    </form>
                </div>

                <table id="comments_dg">
                </table>
            </div>
        </div>
    </div>
    <!--/span-->

</div><!--/row-->
</#macro>

<#macro script>
<script type="text/javascript">
    function getQueryCondition(){
        var content = $("#searchContent").val();
        return {"content":content};
    }
    function queryData(){
        var pars=getQueryCondition();
        //构造列表
        jQuery('#comments_dg').datagrid({
            url:'${base}/system/comments/list',
            fitColumns : true,
            striped : true,
            pagination : true,
            rownumbers : true,
            pageSize : 50,
            pageNumber : 1,
            pageList : [ 50, 100, 150, 200, 250],
            loadMsg : '数据正在加载中...',
            singleSelect:true,
            queryParams : pars,
            selectOnCheck : false,
            checkOnSelect : false,
            width:$('.box-content').width() * 0.985,
            columns : [[
                {field : 'commentContent', title : '内容',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.1, align: 'center'},
                {field : 'commentPost', title : '评论文章',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center',
                    formatter:function(value,row,index){
                        var url = "${base}/posts/" + row.commentPostId;
                        return "<a target='_blank' href='" + url +"'>点击打开</a>";
                    }
                },
                {field : 'commentAuthor', title : '评论人',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center',
                    formatter:function(value,row,index){
                        return "<a href='${base}/profile?userId=" + row.commentAuthor + "'>" + row.commentAuthorName +"</a>";
                    }
                },
                {field : 'commentAuthorIp', title : '评论人IP',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'createTimeStr', title : '评论时间',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'ctrl', title : '是否显示',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.03, align: 'center',
                    formatter:function(value,row,index){
                        var select = "<input data-no-uniform='true' data-id=" + row.id;
                                if(row.commentApproved == 1)
                                    select += " checked";
                                select += " type='checkbox' onchange='changeStatus(this," + row.id + ","+ row.commentApproved +")' class='iphone-toggle'>";
                        return select;
                    }
                }
            ]],
            onLoadSuccess:function(data){
                $('.iphone-toggle').iphoneStyle({
                    checkedLabel: '显示',
                    uncheckedLabel: '隐藏',
                    onChange:function(e,checked){
                        var approved = 0;
                        if(checked) approved = 1;
                        jQuery.ajax({
                            type: "POST",
                            url: '${base}/system/comments/changeStatus',
                            dataType:"json",
                            data: {"id": $(e).data("id"),"approved":approved},
                            success: function(data){
                                if(data.status == 1) {
                                    console.info("操作成功！");
                                }else{
                                    alert("操作失败！");
                                }
                            },
                            error: function (obj){
                                console.info(obj);
                            }
                        });
                    }
                });
            },
            onClickRow: function (rowIndex, rowData) {

            }
        });
    }

    $(document).ready(function () {
        queryData();
    });
</script>
</#macro>
